<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <!-- （后窗、ufb、fb1、其他、缓存区） -->
        <label class="el-form-item-label">仓库名称</label>
        <!-- <el-input v-model="query.whWarehouseName" clearable placeholder="仓库名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <el-select v-model="form.whWarehouseName" style="width: 185px;" class="filter-item" placeholder="请选择字段名" @change="crud.toQuery">
          <el-option
            v-for="item in dict.wh_warehouse_name"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <label class="el-form-item-label">库区</label>
        <el-input v-model="query.warehouseZonesType" clearable placeholder="库区" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">储位编码</label>
        <el-input v-model="query.storageCode" clearable placeholder="储位编码" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">储位类型</label>
        <el-input v-model="query.storageType" clearable placeholder="储位类型" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="仓库名称">
            <el-select v-model="form.whWarehouseName" style="width: 250px;" placeholder="请选择字段名">
              <el-option
                v-for="item in dict.wh_warehouse_name"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="库区">
            <el-input v-model="form.warehouseZonesType" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位编码">
            <el-input v-model="form.storageCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="储位类型">
            <el-input v-model="form.storageType" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="占用情况">
            <el-select v-model="form.takeStatus" style="width: 250px;" placeholder="请选择">
              <el-option
                v-for="item in dict.semi_take_status"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="锁定情况">
            <el-select v-model="form.lockStatus" style="width: 250px;" placeholder="请选择">
              <el-option
                v-for="item in dict.semi_lock_status"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="行">
            <el-input v-model="form.xPath" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="排">
            <el-input v-model="form.yPath" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="层">
            <el-input v-model="form.zPath" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="乐观锁">
            <el-input v-model="form.version" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.note" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="组储位编号">
            <el-input v-model="form.pairCode" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="队列">
            <el-select v-model="form.queue" style="width: 250px;" placeholder="请选择">
              <el-option
                v-for="item in dict.semi_storage_queue"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="whWarehouseName" label="仓库名称">
          <template slot-scope="scope">
            {{ dict.label.semi_warehouse_name[scope.row.whWarehouseName] }}
          </template>
        </el-table-column>
        <el-table-column prop="warehouseZonesType" label="库区" />
        <el-table-column prop="storageCode" label="储位编码" />
        <el-table-column prop="storageType" label="储位类型" />
        <el-table-column prop="takeStatus" label="占用情况">
          <template slot-scope="scope">
            {{ dict.label.semi_take_status[scope.row.takeStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="lockStatus" label="锁定情况">
          <template slot-scope="scope">
            {{ dict.label.semi_lock_status[scope.row.lockStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="xPath" label="行" />
        <el-table-column prop="yPath" label="排" />
        <el-table-column prop="zPath" label="层" />
        <el-table-column prop="version" label="乐观锁" />
        <el-table-column prop="note" label="备注" />
        <el-table-column prop="pairCode" label="组储位编号" />
        <el-table-column prop="queue" label="队列">
          <template slot-scope="scope">
            {{ dict.label.semi_storage_queue[scope.row.queue] }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWhStorageLocation from '@/api/jtWork/jtStorage'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, whWarehouseName: null, warehouseZonesType: null, storageCode: null, storageType: null, takeStatus: null, lockStatus: null, xPath: null, yPath: null, zPath: null, version: null, createTime: null, updateTime: null, createName: null, updateName: null, note: null, pairCode: null, queue: null }
export default {
  name: 'JtStorage',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['semi_take_status', 'semi_lock_status', 'semi_warehouse_name', 'semi_storage_queue'],
  cruds() {
    return CRUD({ title: 'whStorageLocation', url: 'semiApi/whStorageLocation', idField: 'id', sort: 'id,desc', crudMethod: { ...crudWhStorageLocation }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'whStorageLocation:add', 'otherUser'],
        edit: ['admin', 'whStorageLocation:edit', 'otherUser'],
        del: ['admin', 'whStorageLocation:del', 'otherUser']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'whWarehouseName', display_name: '仓库名称' },
        { key: 'warehouseZonesType', display_name: '库区' },
        { key: 'storageCode', display_name: '储位编码' },
        { key: 'storageType', display_name: '储位类型' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
